#pragma once
#include <list>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
#include "Xps/Util/concurrent_queue.h"
#include "Xps/Protocol/IProtocol.h"
#include "Xps/Packet/IPacket.h"
#include "Xps/Object/IObjectFactory.h"

namespace Xps
{
    namespace TCP
    {
        namespace asio = boost::asio;
        using namespace boost::asio::ip;

        class ClientSession
        {
        public:
            typedef boost::shared_ptr<ClientSession> Ptr;
            typedef IProtocol::concurrent_in_queue concurrent_in_queue;

            ClientSession(asio::io_service &_io_service,
                concurrent_in_queue &_incomming_queue, HANDLE _RecieveEvent, const IObjectFactory *_ObjectFactory);
            ~ClientSession(void);

            tcp::socket & getSocket();
            bool IsRunning() const;
            void Start();
            void Stop();
            void Send(IPacket::Ptr _Packet);

        private:
            void Run();

            bool is_running;
            tcp::socket socket;
            boost::thread m_thread;
            concurrent_in_queue &incomming_queue;
            HANDLE recieve_event;
            const IObjectFactory *object_factory;
        };
    };
};
